﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiLibrary.PermissionsValidation;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemManager;
using SystemCenterSoa.Service.SystemManager;

namespace SystemCenterSoa.ApiProject.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //-[ServiceFilter(typeof(UserTokenVerificationAttribute))]
    public class MyBaseController : ControllerBase
    {
        public LoginUserDto LoginUser
        {
            get
            {
                return AdminUserService.GetLoginUser();   
            }
        }
        protected ResultModel<T> MyOk<T>(T data, string mess = "执行成功")
        {
            ResultModel<T> resultModel = new ResultModel<T>();
            resultModel.data = data;
            resultModel.code = ResultCode.Ok;
            resultModel.mess = mess;
            return resultModel;
        }

        protected ResultModel<T> MyError<T>(Exception ex, string mess = "出现错误")
        {
            ResultModel<T> resultModel = new ResultModel<T>();

            resultModel.code = ResultCode.Error;
            resultModel.mess = mess + "错误信息是:" + ex.ToString();
            return resultModel;
        }

        protected ResultModel<T> MyFail<T>(string mess = "出现错误")
        {
            ResultModel<T> resultModel = new ResultModel<T>();

            resultModel.code = ResultCode.Fail;
            resultModel.mess = mess;
            return resultModel;
        }
    }
}
